<template>
  <t-dialog
    :header="getHeader"
    :visible.sync="visible"
    :onClose="closeDialog"
    :closeOnOverlayClick="false"
    :confirmBtn="null"
    width="80%"
    top="5%"
  >
    <t-tabs placement="left"  size="medium" v-model="stepValue">
      <t-tab-panel  value="1" label="申报详情">
         <t-sticky-tool
            v-if="!hideInfo"
            :style="{ position: 'absolute', overflow: 'hidden',zIndex: 1000 }"
            :offset="[-40, -20]"
            @click="createPDF(1)"
          >
            <t-sticky-item  label="导出PDF" >
              <template #icon>
                <t-icon name="file-pdf"></t-icon>
              </template>
            </t-sticky-item>
          </t-sticky-tool>
        <item-detail :obj-id="objId" :hide-info="hideInfo"></item-detail>
      </t-tab-panel>
      <t-tab-panel value="2" label="任务书详情">
        <t-sticky-tool
            v-if="!hideInfo && openRWS"
            :style="{ position: 'absolute', overflow: 'hidden',zIndex: 1000 }"
            :offset="[-40, -20]"
            @click="createPDF(3)"
          >
            <t-sticky-item  style="width: 90px" label="导出任务书PDF" >
              <template #icon>
                <t-icon name="file-pdf"></t-icon>
              </template>
            </t-sticky-item>
          </t-sticky-tool>
        <contract-detail v-if="openRWS" :obj-id="objId" :row="row"></contract-detail>
        <div v-else style="height: 65vh;display: flex;justify-content: center;align-items: center;font-weight: bold;font-size: 50px;color: #ccc;">待签订任务书...</div>
      </t-tab-panel>
      <t-tab-panel  value="3" label="实施变更申请">
        <change-apply-list :projectId="objId"></change-apply-list>
      </t-tab-panel>
      <!-- <t-tab-panel  value="4" label="实施执行情况报告">
        <performance-report-list :projectId="objId"></performance-report-list>
      </t-tab-panel>
      <t-tab-panel value="5" label="年度经济效益">
        <project-benefit :objId="objId" :project-name="getHeader" :edit-open="true"></project-benefit>
      </t-tab-panel> -->
      <t-tab-panel value="6" label="验收详情">
          <acceptance-detail-dialog  v-if="openYS" :header="header" :row="row" :isDialog="false"  :objId="objId" ></acceptance-detail-dialog>
          <div v-else style="height: 65vh;display: flex;justify-content: center;align-items: center;font-weight: bold;font-size: 50px;color: #ccc;">待验收申请...</div>
      </t-tab-panel>
    </t-tabs>
  </t-dialog>
</template>

<script>
import itemDetail from "./item-detail.vue";
import contractDetail from "../../contract/components/contract-detail.vue";
import ChangeApplyList from "../../implement/components/change-apply-list.vue";
import performanceReportList from "../../implement/components/performance-report-list.vue";
import ProjectBenefit from "../../achievement/components/project-benefit.vue";
import AcceptanceDetailDialog from "../../acceptance/components/acceptance-detail-dialog.vue";


export default {
  name: "item-detail-dialog",
  components:{
    itemDetail,
    contractDetail,
    ChangeApplyList,
    performanceReportList,
    ProjectBenefit,
    AcceptanceDetailDialog
  },
  props:{
    objId: [String,Number],
    header: String,
    row: Object,
    hideInfo: {
      type: Boolean,
      default: false
    },
    tabDefaultValue: {
      type: String,
      default: '1'
    }
  },
  data(){
    return {
      visible: true,
      stepValue: this.tabDefaultValue,
      openRWS: false,
      openYS: false,
      rwsHeader: '',
    }
  },
  computed:{
    getHeader(){
      let header = ''
      if(this.rwsHeader){
        header = this.rwsHeader
      }
      if(this.header && !this.rwsHeader){
        header = this.header
      }
      return header
    }
  },
  created() {
    this.getProject();
    this.checkRWS();
    this.checkYS();
  },
  methods:{
    checkYS(){
      this.$api.kjxm.acceptance.getByProject(this.objId).then(response => {
        if(response.data){
          this.openYS = true
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    createPDF(type){
      const instance = this.$loading({
        fullscreen: true,
        attach: 'body',
        preventScrollThrough: false,
      });
      if(type===1){
        this.$api.kjxm.project.projectTestPDF(this.objId).then(response => {
          window.open(response.data.fullFilePath, '_blank')
          instance.hide();
        }).catch((e) => {
          instance.hide();
          this.$message.error(e.toString());
        });
      }else if(type===3){
        this.$api.kjxm.contract.createPDF(this.objId, this.isReview?2:1).then(response => {
          window.open(response.data.fullFilePath, '_blank')
          instance.hide();
        }).catch((e) => {
          instance.hide();
          this.$message.error(e.toString());
        });
      }
    },
    getProject(){
      this.$api.kjxm.project.get(this.objId).then(response => {
        this.header = response.data.projectName;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    checkRWS(){
      this.$api.kjxm.contract.getByProject(this.objId).then(response => {
        if(response.data){
          this.openRWS = true
          this.rwsHeader = response.data.projectName;
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    closeDialog() {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style scoped>

</style>
